layui.use(['element', 'table', 'tree', 'zlpoptree', 'zlContext', 'zlConfig', 'treeGrid', 'zlPopSourceForm', 'zlPinYin', 'zlSelectEx'], function (exports) {
  $ = layui.$;
  var $ = layui.$
    , zlContext = layui.zlContext
    , element = layui.element
    , layer = layui.layer
    , table = layui.table
    , zlComponentRender = layui.zlComponentRender
    , zlConfig = layui.zlConfig
    , statusName = zlConfig.global.result.statusName
    , msgName = zlConfig.global.result.msgName
    , dataName = zlConfig.global.result.dataName
    , ERROR = zlConfig.global.result.errorState
    , OK = zlConfig.global.result.okState
    , form = layui.form
    , treeGrid = layui.treeGrid
    , fullheight = zlContext.setMaxHeihgt(0);
  var setting = {
    view: {
      showLine: true
    },
    async: {
      enable: true,
      url: layui.cache['contentPath'] + "/manager/corefunction/queryOrgddata",
      type: "get",
      dataFilter: function ajaxDataFilter(treeId, parentNode, responseData) {
        if (responseData[statusName] == OK) {
          var data = responseData[dataName];
          for (var i = 0 ;i < data.length;i++){         
            data[i].icon = layui.cache['contentPath']+ "/static/image/org.png";
          }
          return data;
        }
        else {
          zlContext.errorMsg(responseData[msgName]);
        }
        return responseData;
      }
    },
    data: {
      key: {
        name: "OBJNAME"
      }
      , simpleData: {
        enable: true
        , idKey: "RWID"
        , pIdKey: "SYS_PARENTID"
        , rootPid: ""
      }
    },
    callback: {
      onClick: function (event, treeId, treeNode) {
        $('input[name="ORGIDTEMP"]').val(treeNode.RWID);
        treeGrid.reload('treeTable', {
          url: layui.cache['contentPath'] + '/manager/coremenu/query?orgid=' + $('input[name="ORGIDTEMP"]').val()
          , height : fullheight
        });
      }
    }
  };
  $.fn.zTree.init($("#orgtree"), setting, null);

  $(window).on('resize', function () {
	  zlContext.setMaxHeihgt(0);
  }).resize();
});


